<?php

class Show extends TPage
{
	public $element_manager;
	public $element;
	
	public function onLoad($param)
	{
		parent::onLoad($param);
		$this->element_manager = $this->Application->Modules['conference_elements'];
		
		$this->element = $this->element_manager->getConferenceElementById($this->Request['id']);
		if(!($this->element instanceof ConferenceElementRecord))
			$this->Response->redirect($this->Service->constructUrl('ConferencePlan'));
			
		if(!$this->IsPostback)
		{
			$this->readData();
		}
	}
	
	public function readData()
	{
		$requested_manager = $this->Application->Modules['requested_elements'];
		$this->RequestedElementList->DataSource = $requested_manager->getRequestedElementsListBySessionId(
													$this->element->getId());
		$this->RequestedElementList->dataBind();
	}
	
	public function getQuantity()
	{
		
		$quantity = $this->element->getQuantity();
		if($quantity !== null)
		{
			$manager = $this->Application->Modules['users_conference_elements'];
			$reserved = $manager->countUserConferenceElementsByConferenceElementId($this->element->getId());
			$quantity = $reserved.'/'.$quantity;
		}
		else
			$quantity = '-';
			
		return $quantity;
	}
	
	public function getCurrencyName()
	{
		$setting_manager = $this->Application->Modules['settings'];
		if($setting = $setting_manager->getSettingByName(SettingManager::$CURRENCY_NAME))
			return $setting->getValue() != '' ? $setting->getValue() : '-';
		return '-';
	}
	
	public function getUserName($user_id)
	{
		$user_manager = $this->Application->Modules['users'];
		$user = $user_manager->getUserById($user_id);
		
		if($user)
			return $user->getFullName();
		return '-';
	}
	
	public function getPlace()
	{
		$text = '-';
		if($this->element->place)
		{
			$text = $this->element->place->getName();
			if($this->element->place->getDescription())
				$text .=  '<br/><em>'.$this->element->place->getDescription().'</em>';
		}
		return $text;
	}
	
	public function getAddress()
	{
		if($this->element->place)
		{
			$address_id = $this->element->place->getAddressId();
			$address_manager = $this->Application->Modules['addresses'];
			$address = $address_manager->getAddressById($address_id);
			if($address)
			{
				$s = $address->getStreet();
				$s .= $s != '' ? ' ' : '';
				$s .= $address->getNumber();
				
				$p = $address->getPostalCode();
				$p .= $p != '' ? ' ' : '';
				$p .= $address->getCity();
				
				$c = $address->getCountry();
				$d = $this->element->place->getDescription();
				
				$text = $s;
				if($s != '')
					$text .= '<br/>';
				$text .= $p;
				if($p != '')
					$text .= '<br/>';
				$text .= $c;
				if($c != '' && $d != '')
					$text .= '<br/>';
				if($d != '')
					$text .= '<em>'.$d.'</em>';
					
				return $text;
			}
		}
		return '-';
	}
}

?>